angular.module("driver").run(["$rootScope", "$location", function($rootScope,
  $location) {
  $rootScope.$on("$stateChangeError", function(event, next, previous,
    error) {
    // We can catch the error thrown when the $requireUser promise is rejected
    // and redirect the user back to the main page
    if (error === "AUTH_REQUIRED") {
      $location.path("/main/amap");
    }
  });
}]);
/*
Router.route('/', function() {
  this.render('default');
});

 iron-router
 http://stackoverflow.com/questions/31035196/iron-router-conflict-with-angular-ui-router
*/

angular.module("driver").config(['$urlRouterProvider', '$stateProvider',
  '$locationProvider',
  function($urlRouterProvider, $stateProvider, $locationProvider) {

    //$locationProvider.html5Mode(false);
    $stateProvider
      .state('main', {
        url: "/main",
        abstract: true,
        templateUrl: "client/driver/views/main.ng.html",
        controller: 'MainCtrl'
      })

    .state('main.list', {
        url: '/list',
        views: {
          'menuContent': {
            templateUrl: 'client/driver/views/list.ng.html',
            controller: 'ListCtrl'
          }
        }
      })
      .state('main.amap', {
        url: '/amap',
        views: {
          'menuContent': {
            templateUrl: 'client/driver/views/amap.ng.html',
            controller: 'MapCtrl'
          }
        }
      })
      .state('account', {
        url: '/account',
        templateUrl: 'client/driver/views/account.ng.html',
        controller: 'AccountCtrl'
          //templateUrl: 'client/parties/views/todo-view.ng.html',
          //controller: 'TodoCtrl'
      })
      .state('register', {
        url: '/register',
        templateUrl: 'client/driver/views/register.ng.html',
        controller: 'RegisterCtrl'
          //templateUrl: 'client/parties/views/todo-view.ng.html',
          //controller: 'TodoCtrl'
      })
      .state('users', {
        url: '/users',
        templateUrl: 'client/driver/views/users.ng.html',
        controller: 'UsersCtrl'
          //templateUrl: 'client/parties/views/todo-view.ng.html',
          //controller: 'TodoCtrl'
      })
      .state('trades', {
        url: '/trades',
        templateUrl: 'client/driver/views/trades.ng.html',
        controller: 'TradesCtrl'
          //templateUrl: 'client/parties/views/todo-view.ng.html',
          //controller: 'TodoCtrl'
      })
      .state('order', {
        url: '/order',
        templateUrl: 'client/driver/views/order.ng.html',
        controller: 'OrderCtrl'
          //templateUrl: 'client/parties/views/todo-view.ng.html',
          //controller: 'TodoCtrl'
      })
      .state('invoice', {
        url: '/invoice',
        templateUrl: 'client/driver/views/invoice.ng.html',
        controller: 'InvoiceCtrl'
          //templateUrl: 'client/parties/views/todo-view.ng.html',
          //controller: 'TodoCtrl'
      })
      .state('market', {
        url: '/market',
        templateUrl: 'client/driver/views/market.ng.html',
        controller: 'MarketCtrl'
          //templateUrl: 'client/parties/views/todo-view.ng.html',
          //controller: 'TodoCtrl'
      })
      .state('more', {
        url: '/more',
        templateUrl: 'client/driver/views/more.ng.html',
        controller: 'MoreCtrl'
          //templateUrl: 'client/parties/views/todo-view.ng.html',
          //controller: 'TodoCtrl'
      })
      .state('price', {
        url: '/price',
        templateUrl: 'client/driver/views/price.ng.html',
        controller: 'PriceCtrl'
          //templateUrl: 'client/parties/views/todo-view.ng.html',
          //controller: 'TodoCtrl'
      })
       .state('rule', {
        url: '/rule',
        templateUrl: 'client/driver/views/rule.ng.html',
        controller: 'RuleCtrl'
          //templateUrl: 'client/parties/views/todo-view.ng.html',
          //controller: 'TodoCtrl'
      })
      .state('onesdata', {
        url: '/onesdata',
        templateUrl: 'client/driver/views/onesdata.ng.html',
        controller: 'OnesdataCtrl'
          //templateUrl: 'client/parties/views/todo-view.ng.html',
          //controller: 'TodoCtrl'
      })
      .state('aboutus', {
        url: '/aboutus',
        templateUrl: 'client/driver/views/aboutus.ng.html',
        controller: 'AboutusCtrl'
          //templateUrl: 'client/parties/views/todo-view.ng.html',
          //controller: 'TodoCtrl'
      })
      .state('needriver', {
        url: '/needriver',
        templateUrl: 'client/driver/views/needriver.ng.html',
        controller: 'NeedriverCtrl'
          //templateUrl: 'client/parties/views/todo-view.ng.html',
          //controller: 'TodoCtrl'
      })
      /*.state('arounds', {
        url: '/arounds',
        templateUrl: 'client/driver/views/arounds.ng.html',
        controller: 'AroundCtrl'
          //templateUrl: 'client/parties/views/todo-view.ng.html',
          //controller: 'TodoCtrl'
      })*/
      .state('driverinfo', {
        url: '/driverinfo',
        templateUrl: 'client/driver/views/driverinfo.ng.html',
        controller: 'driverinfoCtrl'
      })
      .state('requestinfo', {
        url: '/requestinfo/:reqId',
        templateUrl: 'client/driver/views/requestinfo.ng.html',
        controller: 'requestinfoCtrl'
      })
      .state('adminapplys', {
        url: '/adminapplys',
        templateUrl: 'client/driver/views/admin.applys.ng.html',
        controller: 'AdminApplysCtrl'
      });

    $urlRouterProvider.otherwise("/main/amap");
  }
]);
